#include <stdio.h>
#include <string.h>
#include <ctype.h>

int prepara_key(char *key)
{
    register char *p, *dup;
    int ch;

    if (*key == '\0')
        return 0;

    for (p = key; (ch = *p) != '\0'; p++)
    {
        if (!islower(ch))
        {
            if (!isupper(ch))
                return 0;

            *p = tolower(ch);
        }
    }

    for (p = key; (ch = *p) != '\0';)
    {
        dup = ++p;
        while ((dup = strchr(dup, ch)) != NULL)
            strcpy(dup, dup + 1);
    }

    for (ch = 'a'; ch <= 'z'; ch++)
    {
        if (strchr(key, ch) == NULL)
        {
            *p++ = ch;
            *p = '\0';
        }
    }
}